package com.uetoken.cn.activity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.EncodeUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.jungly.gridpasswordview.GridPasswordView;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.sulink.numberkeyboard.popWindow.BasePayPop;
import com.sulink.numberkeyboard.popWindow.SimplePayPopWindow;
import com.uetoken.cn.R;
import com.uetoken.cn.adapter.PaymentMethodAdapter;
import com.uetoken.cn.base.BaseActivity;
import com.uetoken.cn.bean.PayPrepareBean;
import com.uetoken.cn.bean.PaySuccessBean;
import com.uetoken.cn.bean.PaymentMethodBean;
import com.uetoken.cn.common.ApiHelper;
import com.uetoken.cn.common.Constant;
import com.uetoken.cn.network.OkHttpUtils;
import com.uetoken.cn.network.Params;
import com.uetoken.cn.network.WebResponse;
import com.uetoken.cn.utils.ClickUtils;
import com.uetoken.cn.utils.CompareNumberSizeUtils;
import com.uetoken.cn.utils.GlideApp;
import com.uetoken.cn.utils.KeybordUtils;
import com.uetoken.cn.utils.Save2DecimalUtils;
import com.uetoken.cn.view.DialogHelper;
import com.xuelianx.fingerlib.FingerprintScanHelper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * @author 谢杨
 * @date 2018年7月27日14:51:45
 * 从优谷或者PCN跳转的支付界面
 */
public class PayToMerchantsActivity extends BaseActivity implements WebResponse, FingerprintScanHelper.Callback {
    @BindView(R.id.ll_activity_pay_to_merchants_content)
    LinearLayout mLlcontent;
    @BindView(R.id.tv_activity_pay_to_merchants_title)
    TextView mTvTitle;
    @BindView(R.id.tv_activity_pay_to_merchants)
    TextView mTvPayToMerchants;
    @BindView(R.id.tv_activity_pay_to_merchants_money)
    TextView mTvMoney;
    @BindView(R.id.iv_activity_pay_to_merchants_photo)
    QMUIRadiusImageView mIvAPhoto;
    @BindView(R.id.tv_activity_pay_to_merchants_name)
    TextView mTvName;
    @BindView(R.id.tv_activity_pay_to_merchants_confirm_pay)
    TextView mTvConfirmPay;
    @BindView(R.id.tv_activity_pay_to_merchants_pay_style)
    TextView mTvPayStyle;
    @BindView(R.id.rl_activity_pay_to_merchants_pay_style)
    RelativeLayout mRlPayStyle;
    /**
     * 网络请求码
     */
    private static final int NETWORK_RQUEST_PAY_PREPARE = 10;
    private static final int NETWORK_REQUEST_PAY = 30;

    private PayPrepareBean payPrepareBean;
    /**
     * 当前选择的钱包类型
     */
    private String selectpayType;
    /**
     * 当前选择的钱包的图标
     */
    private String selectIcon;
    /**
     * 当前选择的图标的名字
     */
    private String selectPursename;
    /**
     * 当前选择钱包的余额
     */
    private String selectBalance;

    /**
     * 商品类型
     */
    private String subject;


    /**
     * 商家名称(优谷或者pcn)
     */
    private String merchant;
    /**
     * 实际消费金额，经过接口转换的金额
     */
    private String actualAmount;
    /**
     * 被选中的钱包单位
     */
    private String purseunitName;
    /**
     * 免密支付需要和此金额进行对比
     */
    private String amountorig;
//    private String balanceformat;
    private List<PaymentMethodBean> mPaymentMethodBeanList = new ArrayList<>();
    //    private Dialog paypwdDialog;
    private PayPasswordViewHolder payPasswordViewHolder;
    /**
     * json转换为map(需要将此map作为参数传入接口)
     */
    private Map maps;
    private boolean isFreeSecret = true;
    private boolean isFingerprintPayment = false;
    private String notpwdpaytype;
    private FingerprintScanHelper mFingerprintScanHelper;

    @Override
    public int getLayoutId() {
        return R.layout.activity_pay_to_merchants;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        BarUtils.setStatusBarColor(this, ContextCompat.getColor(this, R.color.color_app_theme), true);
        mTvTitle.setText(getString(R.string.str_confirm_payment));
    }

    @Override
    public void initData() {
        notpwdpaytype = SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_USER_INFO).getString(Constant.SP_NOT_PWD_PAY_TYPE, "");
        updataData();
    }

    @Override
    public void init() {

    }

    @Override
    protected void onPause() {
        super.onPause();
        SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_OTHER_INFO).put(Constant.THRID_APP_JSON_DATA, "");
        SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_OTHER_INFO).put(Constant.THRID_APP_MERCHANT, "");
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
//        updataData();
    }

    /**
     * 每次启动支付界面更新信息
     */
    private void updataData() {
        //如果支付成功的界面在栈中就关闭，防止栈中出现多个PaySuccessActivity
        if (ActivityUtils.isActivityExistsInStack(PaySuccessActivity.class)) {
            ActivityUtils.finishActivity(PaySuccessActivity.class);
        }

        mTvMoney.setText("");
        mTvPayStyle.setText("");
        mTvName.setText("");

        merchant = SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_OTHER_INFO).getString(Constant.THRID_APP_MERCHANT, "");
        //pcn或者优谷跳转过来传递的json数据
        String json = SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_OTHER_INFO).getString(Constant.THRID_APP_JSON_DATA, "");
        if (Constant.isTestMode) {
            DialogHelper.showMessageDialog(this, "测试", json, "确定", null, new QMUIDialogAction.ActionListener() {
                @Override
                public void onClick(QMUIDialog dialog, int index) {
                    dialog.dismiss();
                }
            }, null);
        }
        LogUtils.dTag("PayToMerchantsActivity==", "PayToMerchantsActivity== json = " + json + " merchant = " + merchant);
        try {
            JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
            subject = jsonObject.get("subject").getAsString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        /*if (merchant.equals("yougu")) {
            mIvAPhoto.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_yougu));
            mTvPayToMerchants.setText(String.format(getResources().getString(R.string.str_pay_to_certain), getResources().getString(R.string.str_yg)));
        } else if (merchant.contains("believe")) {
            mIvAPhoto.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_uetoken));
            mTvPayToMerchants.setText(String.format(getResources().getString(R.string.str_pay_to_certain), "UE Token"));
        } else {
            mIvAPhoto.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_pcn));
            mTvPayToMerchants.setText(String.format(getResources().getString(R.string.str_pay_to_certain), "Pcn"));
        }*/
        mTvPayToMerchants.setText(String.format(getResources().getString(R.string.str_pay_to_certain), ""));
        try {
            maps = JSON.parseObject(json);
        } catch (Exception e) {
            e.printStackTrace();
            mTvConfirmPay.setEnabled(false);
            mTvConfirmPay.setBackgroundColor(ContextCompat.getColor(this, R.color.app_color_common_gray));
        }
        showLoading();
        OkHttpUtils.getInstance().getStringWithParam(PayToMerchantsActivity.this, ApiHelper.getPayPrepareUrl(), NETWORK_RQUEST_PAY_PREPARE,
                Params.getPayPrepareParams(maps));
    }


    @OnClick({R.id.tv_activity_pay_to_merchants_confirm_pay, R.id.rl_activity_pay_to_merchants_pay_style})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_activity_pay_to_merchants_confirm_pay:
                //是否有支付密码
                boolean isPayPwd = SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_USER_INFO).getBoolean(Constant.IS_PAY_PWD, true);
                if (isPayPwd) {
                    //没有支付密码
                    new QMUIDialog.MessageDialogBuilder(this)
                            .setTitle(getResources().getString(R.string.str_not_setting_pay_pwd))
                            .setMessage(getResources().getString(R.string.str_you_not_setting_pay_pwd_not_user))
                            .addAction(getResources().getString(R.string.str_later), new QMUIDialogAction.ActionListener() {
                                @Override
                                public void onClick(QMUIDialog dialog, int index) {
                                    dialog.dismiss();
                                }
                            })
                            .addAction(getResources().getString(R.string.str_right_now_setting), new QMUIDialogAction.ActionListener() {
                                @Override
                                public void onClick(QMUIDialog dialog, int index) {
                                    dialog.dismiss();
                                    Intent settingPayPwdIntent = new Intent(PayToMerchantsActivity.this, ForgetPasswordActivity.class);
                                    settingPayPwdIntent.putExtra("pwd", "pay");
                                    startActivity(settingPayPwdIntent);

                                }
                            }).show();
                } else {
                    //余额小于消费金额直接提示余额不足
                    if (ObjectUtils.isEmpty(selectBalance)){
                        ToastUtils.showShort(getResources().getString(R.string.network_anomaly_please_again));
                        return;
                    }
                    if (ObjectUtils.isEmpty(actualAmount)){
                        ToastUtils.showShort(getResources().getString(R.string.network_anomaly_please_again));
                        return;
                    }
                    if (Double.parseDouble(selectBalance) < Double.parseDouble(actualAmount)) {
                        ToastUtils.showShort(getResources().getString(R.string.str_insufficient_balance));
                    } else {
                        //最大免密金额
                        String secretAmount = SPUtils.getInstance(Constant.UE_TOKEN_PREFERENCE_USER_INFO).getString(Constant.SP_MAXIMUM_SECRET_AMOUNT, "0");
                        //用于判断是否免密支付
                        int freeSecret = CompareNumberSizeUtils.compare(secretAmount, amountorig);
                        if (payPrepareBean == null) {
                            isFreeSecret = true;
                        } else {
                            if (payPrepareBean.getData() == null) {
                                isFreeSecret = true;
                            } else {
                                isFreeSecret = payPrepareBean.getData().get(0).isIsneedpaypwd();
                            }
                        }
                        if (!isFreeSecret) {
                            //免密金额大于等于消费金额(不需要支付密码)
                            beginPay("");
                        } else {
                            if (notpwdpaytype.contains("1")) {
                                // 指纹支付
                                isFingerprintPayment = true;
                            } else {
                                //免密金额小于消费金额(需要输入支付密码)
                                isFingerprintPayment = false;
                            }
                            showPayPwdDialog();
                        }

                    }
                }
                break;
            case R.id.rl_activity_pay_to_merchants_pay_style:
                showPayDialog();
                break;
        }
    }

    /**
     * 显示支付弹框
     */
    private void showPayPwdDialog() {
        if (!isFingerprintPayment) {
            SimplePayPopWindow popWindow = new SimplePayPopWindow(PayToMerchantsActivity.this);
            actualAmount = String.format("%.2f", Double.parseDouble(actualAmount));

            popWindow.setTvPayValue(actualAmount + purseunitName);//实际支付金额
//                                popWindow.setTvAmount("200CV");//支付总金额
//                                popWindow.setTvDeduction("抵扣100P币");//优惠金额
            popWindow.setPayTypeImageUrl(selectIcon);
            popWindow.setTvPayType(purseunitName);
            selectBalance = Save2DecimalUtils.getDecimalPrecision(selectBalance,2);
            popWindow.setTvBalance(selectBalance);
            popWindow.showAtLocation(mTvConfirmPay, Gravity.BOTTOM, 0, 0);
            popWindow.setOnPayListener(new BasePayPop.PayEnterPassWordListener() {
                @Override
                public void onCancel() {

                }

                @Override
                public void onInputFinished(String passWord) {
                    passWord = EncodeUtils.base64Encode2String(passWord.getBytes());
                    beginPay(passWord);
//                  Toast.makeText(MainActivity.this,"密码："+passWord,Toast.LENGTH_LONG).show();
                }
            });
        } else {
            mFingerprintScanHelper = new FingerprintScanHelper(PayToMerchantsActivity.this);
            mFingerprintScanHelper.setCallBack(this);
            mFingerprintScanHelper.start();
        }
    }

    /**
     * 显示支付方式弹框
     */
    private void showPayDialog() {
        if (mPaymentMethodBeanList.size() != 0) {
            mPaymentMethodBeanList.clear();
        }
        View view = View.inflate(this, R.layout.activity_paymentmethod, null);
        final Dialog dialog = new Dialog(this, R.style.loading_dialog);
        dialog.setContentView(view);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.mIvBack.setImageResource(R.drawable.ic_local_close);
        viewHolder.mTvTitle.setText(getString(R.string.str_please_select_payment_method));
        viewHolder.mPaymentMethod.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        viewHolder.mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });


        List<PayPrepareBean.DataBean> dataBeans = payPrepareBean.getData();
        for (int i = 0; i < dataBeans.size(); i++) {
            PaymentMethodBean paymentMethodBean = new PaymentMethodBean();
            paymentMethodBean.setAmount(String.valueOf(dataBeans.get(i).getAmount()));
            paymentMethodBean.setIcon(dataBeans.get(i).getPursepic());
            paymentMethodBean.setType(dataBeans.get(i).getPursename());
            paymentMethodBean.setBalance(String.valueOf(dataBeans.get(i).getBalance()));
            paymentMethodBean.setPaytype(String.valueOf(dataBeans.get(i).getPaytype()));
            paymentMethodBean.setPurseunitName(dataBeans.get(i).getPurseunitname());
            paymentMethodBean.setAmountorig(String.valueOf(dataBeans.get(i).getAmountorig()));
            paymentMethodBean.setPursetypeid(dataBeans.get(i).getPursetypeid());
            mPaymentMethodBeanList.add(paymentMethodBean);
        }
        PaymentMethodAdapter mPaymentMethodAdapter = new PaymentMethodAdapter(R.layout.item_payment_method, mPaymentMethodBeanList);
        viewHolder.mPaymentMethod.setAdapter(mPaymentMethodAdapter);

        mPaymentMethodAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String amount = mPaymentMethodBeanList.get(position).getAmount();
                String balance = mPaymentMethodBeanList.get(position).getBalance();
                if (Double.parseDouble(balance) > Double.parseDouble(amount)) {
                    selectPursename = mPaymentMethodBeanList.get(position).getType();
                    selectpayType = mPaymentMethodBeanList.get(position).getPaytype();
                    selectIcon = mPaymentMethodBeanList.get(position).getIcon();
                    selectBalance = balance;
                    actualAmount = amount;
                    purseunitName = mPaymentMethodBeanList.get(position).getPurseunitName();
                    amountorig = mPaymentMethodBeanList.get(position).getAmountorig();
                    mTvPayStyle.setText(selectPursename);
                    mTvMoney.setText(Save2DecimalUtils.getDecimalPrecision(actualAmount, 2) + purseunitName);
                    dialog.dismiss();
                }
            }
        });
    }

    @Override
    public void onSuccessResponse(Call call, String response, int requestCode) throws IOException {
        LogUtils.dTag("PayToMerchantsActivity==", "PayToMerchantsActivity== requestCode = " + requestCode + " response = " + response);
        dissmissDialog();
        switch (requestCode) {
            case NETWORK_RQUEST_PAY_PREPARE:
                payPrepareBean = new Gson().fromJson(response, PayPrepareBean.class);
                if (payPrepareBean.getResult() > 0) {
                    List<PayPrepareBean.DataBean> dataBeans = payPrepareBean.getData();

                    //钱包单位
                    purseunitName = String.valueOf(dataBeans.get(0).getPurseunitname());
                    //实际消费金额
                    actualAmount = String.valueOf(dataBeans.get(0).getAmount());
                    selectPursename = dataBeans.get(0).getPursename();
                    selectpayType = String.valueOf(dataBeans.get(0).getPaytype());
                    selectIcon = dataBeans.get(0).getPursepic();
                    selectBalance = String.valueOf(dataBeans.get(0).getBalance());
                    //需要和最大免密金额相比较的字段
                    amountorig = String.valueOf(dataBeans.get(0).getAmountorig());


                    mTvMoney.setText(Save2DecimalUtils.getDecimalPrecision(actualAmount, 2) + purseunitName);
                    mTvPayStyle.setText(selectPursename);
                    mTvName.setText(subject);
                    GlideApp.with(this).load(dataBeans.get(0).getStorelogo()).placeholder(R.drawable.ic_placeholder).into(mIvAPhoto);
                    mTvPayToMerchants.setText(String.format(getResources().getString(R.string.str_pay_to_certain), dataBeans.get(0).getStorename()));
                } else {
                    mRlPayStyle.setClickable(false);
                    mTvConfirmPay.setClickable(false);
                    mTvConfirmPay.setBackgroundColor(Color.parseColor("#CCCCCC"));
                    ToastUtils.showShort(payPrepareBean.getMessage());
//                    if ("订单号重复".equals(payPrepareBean.getMessage())) {
//                        Intent intent = new Intent(this, MainActivity.class);
//                        startActivity(intent);
//                        finish();
//                    } else {
//                        mRlPayStyle.setClickable(false);
//                        mTvConfirmPay.setClickable(false);
//                        mTvConfirmPay.setBackgroundColor(Color.parseColor("#CCCCCC"));
//                        ToastUtils.showShort(payPrepareBean.getMessage());
//                    }
                }
                break;
            case NETWORK_REQUEST_PAY:
                if (ClickUtils.isFastClick()) {
                    PaySuccessBean paySuccessBean = new Gson().fromJson(response, PaySuccessBean.class);
                    if (paySuccessBean.getResult() > 0) {
                        ToastUtils.showShort(paySuccessBean.getMessage());
                        Intent intent = new Intent(PayToMerchantsActivity.this, PaySuccessActivity.class);
                        intent.putExtra("merchant", merchant);
                        intent.putExtra("subject", subject);
                        intent.putExtra("amount", mTvMoney.getText().toString());
                        intent.putExtra("json", response);
                        startActivity(intent);
                        finish();
                    } else {
                        ToastUtils.showShort(paySuccessBean.getMessage());
                    }
                }
                break;
        }

    }


    @Override
    public void onFailResponse(Call call, IOException e, int requestCode) {
        dissmissDialog();
        ToastUtils.showShort(e.getMessage());
    }

    /**
     * 开始支付
     *
     * @param pwd
     */
    private void beginPay(String pwd) {
        showLoading();
        String fingerprint;
        if (isFingerprintPayment) {
            fingerprint = "1";
        } else {
            fingerprint = "0";
        }
        OkHttpUtils.getInstance().getStringWithParam(PayToMerchantsActivity.this, ApiHelper.getPayUrl(), NETWORK_REQUEST_PAY,
                Params.getPayParams("1", selectpayType, pwd, fingerprint, maps));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mFingerprintScanHelper != null) {
            mFingerprintScanHelper.cancelIdentify();
        }
    }

    @Override
    public void onSuccess() {
//        closeView();
        //指纹验证成功
        if (mFingerprintScanHelper != null) {
            mFingerprintScanHelper.cancelIdentify();
        }
        beginPay("");
    }

    @Override
    public void onNotFingerprint() {
        //手机未录入指纹
        if (mFingerprintScanHelper != null) {
            mFingerprintScanHelper.cancelIdentify();
        }
        isFingerprintPayment = false;
        showPayPwdDialog();
    }

    @Override
    public void onDeviceNotSupport() {
        //设备不支持
        if (mFingerprintScanHelper != null) {
            mFingerprintScanHelper.cancelIdentify();
        }
        isFingerprintPayment = false;
        showPayPwdDialog();
    }

    @Override
    public void onError(int code) {
        LogUtils.dTag("PayToMerchantsActivity==", "PayToMerchantsActivity== code = " + code);
        //指纹验证失败
        /**
         * @param code 1 指纹接口错误；2 验证失败，可再试；3 指纹识别次数用完，转输入密码；4 指纹验证太过频繁，转输入密码
         */
        if (code == 1) {
            if (mFingerprintScanHelper != null) {
                mFingerprintScanHelper.cancelIdentify();
            }
            isFingerprintPayment = false;
            showPayPwdDialog();
        } else if (code == 2) {
            if (mFingerprintScanHelper != null) {
                if (payPasswordViewHolder != null) {
                    payPasswordViewHolder.mFingerprintPaymentTv.setText(R.string.str_try_again);
                    payPasswordViewHolder.mFingerprintPaymentTv.setTextColor(getResources().getColor(R.color.color_FB544B));
                    mFingerprintScanHelper.shake(payPasswordViewHolder.mFingerprintPaymentTv);
                }
            }
        } else if (code == 3) {
            if (mFingerprintScanHelper != null) {
                mFingerprintScanHelper.cancelIdentify();
            }
            isFingerprintPayment = false;
            showPayPwdDialog();
        } else if (code == 4) {
            if (mFingerprintScanHelper != null) {
                if (payPasswordViewHolder != null) {
                    payPasswordViewHolder.mFingerprintPaymentTv.setText(R.string.str_fingerprint_verification_often);
                    payPasswordViewHolder.mFingerprintPaymentTv.setTextColor(getResources().getColor(R.color.color_FB544B));
                    mFingerprintScanHelper.shake(payPasswordViewHolder.mFingerprintPaymentTv);
                }
                mFingerprintScanHelper.cancelIdentify();

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        isFingerprintPayment = false;
                        showPayPwdDialog();
                    }
                }, 2000);
            }
        }

    }


    static class ViewHolder {
        @BindView(R.id.iv_back)
        ImageView mIvBack;
        @BindView(R.id.tv_title)
        TextView mTvTitle;
        @BindView(R.id.ry_activity_payment_method)
        RecyclerView mPaymentMethod;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


    static class PayPasswordViewHolder {
        @BindView(R.id.iv_activity_payment_password_close)
        ImageView mIvClose;
        @BindView(R.id.tv_activity_payment_password_merchant)
        TextView mTvMerchant;
        @BindView(R.id.tv_activity_payment_password_money)
        TextView mTvMoney;
        @BindView(R.id.iv_activity_payment_password_icon)
        ImageView mIvIcon;
        @BindView(R.id.tv_activity_payment_password_pursename)
        TextView mTvPursename;
        @BindView(R.id.tv_activity_payment_password_balance)
        TextView mTvBalance;
        @BindView(R.id.ll_activity_payment_password_payment_method)
        LinearLayout mLlMethod;
        @BindView(R.id.gpv_activity_payment_password)
        GridPasswordView mGpvPassword;
        @BindView(R.id.fingerprintPaymentTv)
        TextView mFingerprintPaymentTv;

        PayPasswordViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            if (merchant.equals("yougu")) {
                Intent intentToYG = new Intent();
                intentToYG.setData(Uri.parse("yougu://ue?actionType=3000&json=" + "fail"));
                startActivity(intentToYG);
            } else if (merchant.contains("believe")) {
                Intent intentToUE = new Intent();
                intentToUE.setData(Uri.parse(merchant + "://ue?actionType=8001&message=" + "fail"));
                startActivity(intentToUE);
            } else {
                Intent intentToPcn = new Intent();
                intentToPcn.setData(Uri.parse(merchant + "://ue?actionType=3000&json=" + "fail"));
                startActivity(intentToPcn);
            }
        }
        return true;
    }
}
